﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ZoomEngine.Util;

namespace ZoomEngine.Animation
{
    public class ClockManager
    {
        public ClockManager(Game game)
        {
            Game = game;
        }

        public void Update(GameTime time)
        {
            if (_clocks.Count > 0)
            {
                double elapsedTime = time.ElapsedGameTime.TotalSeconds;
                var readOnlyClocks = _clocks.Open();
                for (int i = 0, count = readOnlyClocks.Count; i < count; i++)
                {
                    readOnlyClocks[i].Update(elapsedTime);
                }
                _clocks.Close();
            }
        }

        internal IList<Clock> Clocks
        {
            get
            {
                return _clocks;
            }
        }

        public Game Game { get; private set; }
        CopyOnWriteCollection<Clock> _clocks = new CopyOnWriteCollection<Clock>();
    }
}
